# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=zlib
_mingw_suff=mingw-w64-cross
pkgname=("${_mingw_suff}-${_realname}")
pkgdesc="Compression library implementing the deflate compression method found in gzip and PKZIP"
pkgver=1.2.8
pkgrel=1
arch=('i686' 'x86_64')
url="http://mingw-w64.sourceforge.net"
license=('custom')
groups=("${_mingw_suff}-toolchain" "${_mingw_suff}")
depends=('')
makedepends=("${_mingw_suff}-gcc")
options=('staticlibs' '!strip' '!libtool' '!emptydirs' '!buildflags')
source=("http://zlib.net/current/${_realname}-${pkgver}.tar.gz"
    01-zlib-1.2.7-1-buildsys.mingw.patch
        02-no-undefined.mingw.patch
        03-dont-put-sodir-into-L.mingw.patch
        04-wrong-w8-check.mingw.patch
        05-fix-a-typo.mingw.patch)
md5sums=('44d667c142d7cda120332623eab69f40'
         '63affd37e371768c6adc6e6561e66daf'
         'cf7e49f23103a7e42c2dee113ea29674'
         'bb6c8eeb7f03978982406bca35f62ca3'
         '94f53bd0a4a4068bcedc195004e70316'
         '076b81ef097c6916cb81daa3ba8c3afa')

_targets="i686-w64-mingw32 x86_64-w64-mingw32"

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  grep -A 24 '^  Copyright' zlib.h > LICENSE

  patch -p2 -i ${srcdir}/01-zlib-1.2.7-1-buildsys.mingw.patch
  patch -p2 -i ${srcdir}/02-no-undefined.mingw.patch
  patch -p2 -i ${srcdir}/03-dont-put-sodir-into-L.mingw.patch
  patch -p2 -i ${srcdir}/04-wrong-w8-check.mingw.patch
  patch -p2 -i ${srcdir}/05-fix-a-typo.mingw.patch
}

build() {
  for _target in ${_targets}; do
    msg "Configuring ${_realname} for ${_target}"
  cp -rf ${srcdir}/${_realname}-${pkgver} ${srcdir}/${_realname}-${_target}
    cd ${srcdir}/${_realname}-${_target}
    CHOST=${_target} ./configure --prefix=/opt/${_target} --shared
  make
  done
}

package() {
  for _target in ${_targets}; do
    msg "Installing ${_realname} for ${_target}"
    cd ${srcdir}/${_realname}-${_target}
    make DESTDIR=${pkgdir} install
  done
}
